package com.yanqu.road.server.cmd.cross.tradewar;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractServerCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TRADE_WAR_PUBLISH_WANTED_TO_WANTED, desc = "跨服商战通缉到被通缉的服务器")
public class CrossTradeWarPublishWantedToWantedCmd extends AbstractServerCommand {

	private int activityId;
	private long wantedUserId;
	private long wantedServerId;
	private long userId;
	private int useItemId;
	private UserBaseInfo userBaseInfo;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarPublishWantedToCrossReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarPublishWantedToCrossReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		userId = reqMsg.getUserId();
		userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseData());
		wantedUserId = reqMsg.getWantedUserId();
		wantedServerId = reqMsg.getWantedServerId();
		useItemId = reqMsg.getUseItemId();
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {
		ret = TradeWarActivityMgr.queryUserCanWanted(activityId,userId, wantedUserId);
	}

	@Override
	public void sendData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarPublishWantedToWantedRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarPublishWantedToWantedRespMsg.newBuilder();
		respMsg.setActivityId(activityId);
		respMsg.setRet(ret);
		respMsg.setUserId(userId);
		respMsg.setUseItemId(useItemId);
		respMsg.setUserBaseData(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));
		if(0 == ret){
			respMsg.setWantedUserId(wantedUserId);
			respMsg.setWantedBaseData(PlayerBasePb.parsePlayerBaseTempMsg(UserMgr.getUserBaseInfo(wantedUserId, GameServer.getInstance().getServerId())));
		}
		int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, userId);
		GamePlayerMgr.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_TRADE_WAR_PUBLISH_WANTED_TO_WANTED_RESP, respMsg, 0, activityId, groupId);
	}
}
